package com.molichuxing.gateway.bff.user.services.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.gateway.bff.user.convertor.Convert;
import com.molichuxing.gateway.bff.user.entity.request.modify.ComplaintModifyVo;
import com.molichuxing.gateway.bff.user.entity.response.ComplaintVo;
import com.molichuxing.gateway.bff.user.services.ComplaintBffService;
import com.molichuxing.services.business.dto.response.ComplaintBizDto;
import com.molichuxing.services.business.service.ComplaintBizService;
import com.molichuxing.services.infrastructure.dto.request.modify.ComplaintModifyDto;
import com.molichuxing.services.infrastructure.dto.response.ComplaintDto;
import com.molichuxing.services.infrastructure.service.ComplaintService;
import com.molichuxing.services.property.ComplaintStatusEnum;

/**
 * 
 * @author liyg
 * 2019-08-29
 * 用户投诉bff服务实现类
 * 
 */
@Service("complaintBffService")
public class ComplaintBffServiceImpl implements ComplaintBffService{

	@Resource
	private ComplaintBizService complaintBizService;
	
	@Resource
	private ComplaintService complaintService;

	
	/**
	 * 获取投诉列表
	 * 
	 * @param map
	 *            参数
	 *key:phone
	 *            String 用户手机号 非必填
	 *key:realName
	 *            String 用户真实姓名 非必填
	 *key:type
	 *            Integer 投诉方式 非必填
	 *key:status
	 *            Integer 投诉处理状态 非必填
	 *key:startTime
	 *            String 投诉开始时间 非必填
	 *key:endTime
	 *            String 投诉结束时间 非必填
	 *key:pageNum
	 *            Integer 当前页
	 *key:pageSize
	 *            Integer 每页显示条数
	 * @return
	 */
	@Override
	public Paged<ComplaintVo> getComplaintList(Map<String, Object> map) {
		
		Paged<ComplaintBizDto> paged = complaintBizService.getComplaintList(map);
		if(null == paged) {
			return new Paged<>();
		}else if(paged.isEmpty()) {
			return new Paged<>(null,paged.getTotal(),paged.getPageSize());
		}
		List<ComplaintBizDto> complaintBizDtoList= paged.getList();
		List<ComplaintVo> complaintVoList = Convert.toComplaintVo(complaintBizDtoList);
		Integer pageSize=paged.getPageSize();
		Long total=paged.getTotal();
		Paged<ComplaintVo> page=new Paged<>(complaintVoList,total,pageSize);
		
		return page;
	}
	
	/**
	 * 获取用户投诉详情
	 * @param complaintId
	 * @return
	 */
	@Override
	public ComplaintVo getComplaint(Integer complaintId) {
		
		ComplaintDto complaint = complaintService.getComplaint(complaintId);
		ComplaintVo complaintVo = Convert.toComplaintVo(complaint);
		
		return complaintVo;
	}
	
	/**
	 * 编辑投诉
	 * 
	 * @param vo
	 *            需要修改的数据实体
	 * @return
	 */
	@Override
	public Boolean modifyComplaint(ComplaintModifyVo vo) {
		
		ComplaintModifyDto modifyDto=new ComplaintModifyDto();
	    modifyDto.setId(vo.getId());
	    modifyDto.setRemark(vo.getRemark());
	    modifyDto.setStatus(ComplaintStatusEnum.PROCESSED.getValue());
	    modifyDto.setOperateId(vo.getOperateId());
	    modifyDto.setOperateName(vo.getOperateName());
	    modifyDto.setOperateDate(DateUtil.convertDateToLDT(new Date()));
		return  complaintService.modifyComplaint(modifyDto);
	}
	
}
